package com.jcooky.tutorfs.proxy.protocol;

import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;

import org.apache.mina.core.buffer.IoBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ReqRead extends AbstractMessage {
	private static final Logger logger = LoggerFactory.getLogger(ReqRead.class);
	
	private String filepath;
	private int pos;
	private int size;

	public void fromBytes(IoBuffer buf) {
		try {
			filepath = buf.getString(256, Charset.forName("UTF-8").newDecoder());
			pos = Integer.reverseBytes(buf.getInt());
			size = Integer.reverseBytes(buf.getInt());
			
			logger.debug("##### filepath : {}, pos : {}, size : {}", new Object[]{filepath, pos, size});
		} catch (CharacterCodingException e) {
			throw new RuntimeException(e);
		}
	}

	public void toBytes(IoBuffer buf) {
		throw new UnsupportedOperationException();
	}

	public int length() {
		return 256 + 4 + 4;
	}

	public String getFilepath() {
		return filepath;
	}

	public void setFilepath(String filepath) {
		this.filepath = filepath;
	}

	public int getPos() {
		return pos;
	}

	public void setPos(int pos) {
		this.pos = pos;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}
	
	

}
